package com.controller.hht;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bean.hht.Intervieweraccess;
import com.bean.hht.Stuinfo;
import com.config.Result;
import com.mapper.hht.AppointMapper;
import com.mapper.hht.IntervieweraccessMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class SetStuStateController {
    @Autowired
    AppointMapper appointMapper;

    @Autowired
    IntervieweraccessMapper intervieweraccessMapper;


    //面试成功
    @GetMapping("/succes")
    public Result succes(@RequestParam("id")int id){
        Stuinfo stu = appointMapper.selectById(id);
        int interviewer_id = stu.getInterviewerid();
        String interviewer_intjob = stu.getIntjob();
        QueryWrapper<Intervieweraccess> wrapper = new QueryWrapper<>();
        HashMap<String, Object> map = new HashMap<>();
        map.put("interid", interviewer_id);
        map.put("intjob", interviewer_intjob);
        wrapper.allEq(map);
        Intervieweraccess intervieweraccess = intervieweraccessMapper.selectOne(wrapper);
        int number = intervieweraccess.getNumber();
        if(number>0) {
            intervieweraccess.setNumber(number - 1);
            intervieweraccessMapper.updateById(intervieweraccess);
            stu.setState("通过");
            appointMapper.updateById(stu);
            return new Result("操作成功");
        }
        else
            return new Result("面试官没有名额了，操作失败!");
    }


    //面试失败
    @GetMapping("/fail")
    public Result fail(@RequestParam("id")int id){
        Stuinfo stu=appointMapper.selectById(id);
        stu.setState("未通过");
        appointMapper.updateById(stu);
        return new Result("操作成功");
    }

}
